/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.constant.enums;

import com.comac.ins.common.core.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 *
 * 数据库建模模型特殊字段名称枚举
 * @author lj
 * @date 2025-01-13
 */
@AllArgsConstructor
@Getter
public enum IsfdDatabaseModelSpecialFieldNameEnum {
    OBJECT_ID("_id", "id"),
    IMPORT_METHOD("importRecord", "导入方式"),
    PARENT_ID("parentId", "父id"),
    TABLE_NAME("tableName", "表名");
    private final String value;
    private final String desc;

    public static String getDescByValue(String value) {
        IsfdDatabaseModelSpecialFieldNameEnum isfdAnalysisApplicationTypeEnum = forValue(value);
        if (isfdAnalysisApplicationTypeEnum == null) {
            return null;
        }
        return isfdAnalysisApplicationTypeEnum.getDesc();
    }

    public static IsfdDatabaseModelSpecialFieldNameEnum forValue(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        for (IsfdDatabaseModelSpecialFieldNameEnum isfdAnalysisApplicationTypeEnum : IsfdDatabaseModelSpecialFieldNameEnum.values()) {
            if (isfdAnalysisApplicationTypeEnum.getValue().equals(value)) {
                return isfdAnalysisApplicationTypeEnum;
            }
        }
        return null;
    }

    public static IsfdDatabaseModelSpecialFieldNameEnum forDesc(String desc) {
        if (desc == null) {
            return null;
        }
        for (IsfdDatabaseModelSpecialFieldNameEnum isfdAnalysisApplicationTypeEnum : IsfdDatabaseModelSpecialFieldNameEnum.values()) {
            if (desc.equals(isfdAnalysisApplicationTypeEnum.getDesc())) {
                return isfdAnalysisApplicationTypeEnum;
            }
        }
        return null;
    }

    public static List<String> allValues() {
        return Arrays.stream(values())
                .map(IsfdDatabaseModelSpecialFieldNameEnum::getValue)
                .collect(Collectors.toList());
    }

}
